using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CodePlex.SpaceBlock;
using CodePlex.Resourceful;
using System.Diagnostics;
using CodePlex.Resourceful.Amazon.S3;
using CodePlex.Resourceful.Microsoft.Azure;

namespace CodePlex.SpaceBlock.UI.Controls.Tools
{
    public partial class AzureSettingsControl : BaseControl
    {

        public AzureSettingsControl()
        {
            InitializeComponent();

            _lookupLink.Text = Properties.Messages.Options_Azure_AzureLookup;
            _createLink.Text = Properties.Messages.Options_Azure_AzureSignup;
            
           


        }

        private bool _initializing;

        public void Initialize(FileSystemInfo info)
        {
            // default service host = azure blob host
            if (string.IsNullOrEmpty(info.PublicSettings.GetIfExists(UIConstants.AzureBlobStorageSettings.ServiceHost)))
            {
                info.PublicSettings[UIConstants.AzureBlobStorageSettings.ServiceHost] = AzureConstants.PublicServiceHost;
            }

            UIUtils.Bind(_accountNameBox, info.PublicSettings, UIConstants.AzureBlobStorageSettings.AccountName);
            UIUtils.Bind(_accessKeyBox, info.PrivateSettings, UIConstants.AzureBlobStorageSettings.AccessKey);
            UIUtils.Bind(_useSSLCheck, info.PublicSettings, UIConstants.S3Settings.UseSSL);
            UIUtils.Bind(_serviceHostBox, info.PublicSettings, UIConstants.S3Settings.ServiceHost);

            _initializing = true;
            UpdateData();
            _initializing = false;
        }

        private void _lookupLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start(Properties.Messages.Urls_Azure_Lookup);
        }

        private void _createLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Process.Start(Properties.Messages.Urls_Azure_Signup);
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }


        private void UpdateData()
        {
            bool isDev = _serviceHostBox.Text == AzureConstants.DevelopmentStorageServiceHost;

        
            _accountNameBox.Enabled = !isDev;
            _useSSLCheck.Enabled = !isDev;
            _accessKeyBox.Enabled = !isDev;

            _useDevStorageCheck.Checked = isDev;
            
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (_initializing)
            {
                return;
            }
            if (_useDevStorageCheck.Checked)
            {
                _accountNameBox.Text = AzureConstants.DevelopmentStorageAccountName;
               
                _useSSLCheck.Checked = false;
               
                _accessKeyBox.Text = AzureConstants.DevelopmentStorageAccountKey;
            
                _serviceHostBox.Text = AzureConstants.DevelopmentStorageServiceHost;

               

            }
            else
            {
                _accountNameBox.Text = "";
               
                _accessKeyBox.Text = "";
               

                _serviceHostBox.Text = AzureConstants.PublicServiceHost;

            }

            UpdateData();




          
        }

       
    }
}

